<template>
  <div class="app-container">
    <!-- 表格-条件筛区域  -->
    <div class="filter-container">
      <el-input placeholder="请输入用户操作" v-model="searchParam.SEARCH_LIKE_operation" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"/>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"> 搜索 </el-button>
    </div>

    <!-- 表格-内容区域 -->
    <el-table v-loading="listLoading" :key="tableKey" :data="tableList" border fit highlight-current-row   style="width: 100%;" >
    
        <el-table-column   v-for="column in columns"  :key="column.prop" 
            :prop="column.prop" 
            :label="column.label" 
            :width="column.width" 
            :align="column.align?column.align:'center'"
            :min-width="column.minWidth" 
            :sortable="column.sortable" 
            :fixed="column.fixed" 
            :type="column.type" :formatter="column.formatter" >
            <template slot-scope="scope"   >
                <img   v-if="column.imgFlag==true"   :src="CMBASE.baseFileContext + scope.row[column.prop]" width="60" height="60"  class="img"/>
                <!-- 行内显示tag标签 -->
                <span  v-else-if="column.tagFlag==true">
                    <span v-for="item in column.tagFormatter" :key="item.value" >
                        <el-tag v-if="item.value==scope.row[column.prop]"   :type="item.type">{{item.text}}</el-tag> 
                    </span>
                </span>
                <span v-else-if="column.formatter"> {{column.formatter(scope.row)}}</span>
                <span v-else>{{scope.row[column.prop]}}</span>
            </template>
        
        </el-table-column>

    </el-table>

    <!-- 表格-页脚区域 -->
    <pagination v-show="tableTotal>0" :total="tableTotal" :page.sync="pageRequest.pageNum" :limit.sync="pageRequest.pageSize" @pagination="getList" />


  </div>
</template>

<script>

import waves from '@/directive/waves' // Waves directive
import Pagination from '@/components/Pagination'
import moment from "moment/moment"; // Secondary package based on el-pagination

export default {
  name: 'system-log',
  components: { Pagination },
  directives: { waves },
  filters: { },
  data() {
      return {
          tableKey: 0,
          tableList: [],//表格数据源
          tableTotal: 0,//表格总条数数据
          listLoading: true,
          pageRequest: { pageNum: 1, pageSize: 10, },
          searchParam:{ SEARCH_LIKE_rolename:''},
          dialogFormVisible: false,//默认不显示弹出框
          operation: true, // true:新增, false:编辑
          editLoading: false,//保存表单时loading框
          columns: [
            {prop: 'username',  label: '用户名',  sortable:false  },
            {prop: 'operation',  label: '用户操作',  sortable:false ,align:'left' },
            {prop: 'method',  label: '请求方法',  sortable:false ,width:'500',align:'left' },
            {prop: 'time',  label: '响应时间(ms)',  sortable:false  },
            {prop: 'channel',  label: '响应时间(ms)',  sortable:false ,tagFlag: true  ,
                      tagFormatter: [
                          { text: '管理后台', value: '1', type: 'default' },
                          { text: '商城客户端', value: '2', type: 'success' },
                      ]  },
            {prop: 'ip',  label: 'IP地址',  sortable:false  },
            {prop: 'address',  label: '所属城市',  sortable:false  },
            {prop: 'createTime',  label: '请求时间',  sortable:false , width: 160,
                formatter: (row) => {
                    return moment(row.createTime).format('YYYY-MM-DD HH:mm:ss')
                }
            },
          ],
      }
  },
  created() {
      this.getList();
  },
  methods: {
    //获取表格数据
    getList() {
        this.listLoading = true
        //【API请求】----获取用户列表数据
        this.$api.getSysLogList(this.pageRequest).then(response => {
            this.tableList = response.data.content
            this.tableTotal = response.data.total
            this.listLoading = false;
        }).catch((res) => {
            this.$message({  message: '用户列表获取失败', type: 'error' })
        })
    },
    //表格数据筛选
    handleFilter() {
        this.pageRequest = {
            pageNum: 1,
            pageSize: 10,
        }
        this.pageRequest.searchParam = this.searchParam
        this.getList()
    },
  }
     
     
}
</script>